package servlet;

import javax.servlet.ServletContext;
import javax.servlet.http.HttpSessionEvent;
import javax.servlet.http.HttpSessionListener;

/**
 * @autor my
 * 2017/9/15.
 */
public class Listener implements HttpSessionListener {
    int count=0;
    @Override
    public void sessionCreated(HttpSessionEvent se) {
        count++;
        ServletContext context=se.getSession().getServletContext();
        context.setAttribute("count",new Integer(count));
        context.log("在线人数为："+count);
        System.out.println(count);
    }

    @Override
    public void sessionDestroyed(HttpSessionEvent se) {
        count--;
        ServletContext context=se.getSession().getServletContext();
        context.log("在线人数为："+count);
        System.out.println(count);
    }
}
